home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / tcsel003.zip / HEXCONV.PAS < prev    next >
Pascal/Delphi Source File  |  1992-10-16  |  762b  |  31 lines

  1. var
  2.   n    : word;
  3.   long : longint;
  4.  
  5. function Byte2Hex(numb : byte): string;       { Converts byte to hex string }
  6.   const
  7.     HexChars : array[0..15] of char = '0123456789ABCDEF';
  8.   begin
  9.     Byte2Hex[0] := #2;
  10.     Byte2Hex[1] := HexChars[numb shr  4];
  11.     Byte2Hex[2] := HexChars[numb and 15];
  12.   end; { Byte2Hex }
  13.  
  14. function Numb2Hex(numb: word): string;        { Converts word to hex string.}
  15.   begin
  16.     Numb2Hex := Byte2Hex(hi(numb))+Byte2Hex(lo(numb));
  17.   end; { Numb2Hex }
  18.  
  19. function Long2Hex(L: longint): string;     { Converts longint to hex string }
  20.   begin
  21.     Long2Hex := Numb2Hex(L shr 16) + Numb2Hex(L);
  22.   end; { Long2Hex }
  23.  
  24.  
  25. begin
  26.   long := 65536;
  27.   n    := 256;
  28.   writeln(Long2Hex(long));
  29.   writeln(Numb2Hex(n));
  30. end.
  31.